// pages/login/information/index.js
import {
  fillInformation
} from '../../../api/user.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    avatarUrl: '',
    nickName: '',
    email: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {
      avatarUrl,
      nickName
    } = getApp().globalData.userInfo;
    this.setData({
      avatarUrl,
      nickName
    })
  },

  /**
   * 完成
   */
  handleComplete() {
    if (this.data.nickName === '') {
      wx.showToast({
        title: '请输入昵称',
        icon: 'none'
      })
    } else {
      fillInformation({
        image: this.data.avatarUrl,
        nickName: this.data.nickName,
        email: this.data.email,
        memberId: getApp().globalData.memberId
      }).then(res => {
        getApp().globalData.isLogin = true;
        getApp().globalData.token = res.token;
        getApp().globalData.memberId = res.id;
        getApp().globalData.openid = res.openId;
        Object.assign(getApp().globalData.userInfo, res);
        wx.navigateBack({});
      })
    }
  },

  onInputNickName(e) {
    this.data.nickName = e.detail.value.trim();
  },
  onInputEmail(e) {
    this.data.email = e.detail.value.trim();
  },

})